﻿<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Base.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    TransceiverList
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
        var _userid = '<%=ViewData("UserID") %>';
        var _transceiverdate = '<%=ViewData("TransceiverDate") %>';
    </script>
    <ext:Viewport ID="ViewPort1" runat="server" Layout="fit">
        <Items>
            <ext:GridPanel ID="GridPanel1" runat="server" AutoExpandColumn="TransceiverDate" Header="false"
                Border="false" TrackMouseOver="true" StripeRows="true">
                <Store>
                    <ext:Store ID="dcTransceiver" runat="server" UseIdConfirmation="true">
                        <Proxy>
                            <ext:HttpProxy Url="/Transceiver/GetTransceiverListStore/" />
                        </Proxy>
                        <AutoLoadParams>
                            <ext:Parameter Name="userid" Value="_userid" Mode="Raw" />
                            <ext:Parameter Name="transceiverdate" Value="_transceiverdate" Mode="Raw" />
                        </AutoLoadParams>
                        <Reader>
                            <ext:JsonReader IDProperty="id" Root="data" TotalProperty="total">
                                <Fields>
                                    <ext:RecordField Name="TransceiverTo" />
                                    <ext:RecordField Name="TransceiverCount" />
                                    <ext:RecordField Name="TransceiverDate" />
                                    <ext:RecordField Name="UserID" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                        <SortInfo Field="TransceiverDate" Direction="DESC" />
                        <Listeners>
                            <Load Handler="updateTotal(#{GridPanel1});" />
                        </Listeners>
                    </ext:Store>
                </Store>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:RowNumbererColumn Width="25" Resizable="false" />
                        <ext:CommandColumn Width="25" Hideable="false" Resizable="false">
                            <Commands>
                                <ext:GridCommand CommandName="edit" Icon="ApplicationFormEdit">
                                    <ToolTip Text="明细" />
                                </ext:GridCommand>
                            </Commands>
                        </ext:CommandColumn>
                        <ext:GroupingSummaryColumn Header="日期" DataIndex="TransceiverDate" Width="50" SummaryType="Max">
                            <Renderer Format="Date" Handler="return(new Date(value.replace('-','/')).format('Y年m月d日'))" />
                            <SummaryRenderer Handler="return ((value === 0 || value > 1) ? value +' 项' : '1 项');" />
                        </ext:GroupingSummaryColumn>
                        <%--<ext:GroupingSummaryColumn Header="发出到" DataIndex="TransceiverTo" Width="130" SummaryType="Count" />--%>
                        <ext:GroupingSummaryColumn Header="总数" DataIndex="TransceiverCount" Width="130" SummaryType="Sum" />
                    </Columns>
                    <Listeners>
                        <WidthChange Handler="updateTotal(#{GridPanel1});" />
                    </Listeners>
                </ColumnModel>
                <TopBar>
                    <ext:Toolbar ID="Toolbar1" runat="server">
                        <Items>
                            <ext:Button ID="Button3" runat="server" Text="填写报告" Icon="Add">
                                <Listeners>
                                    <Click Handler="fillToday();" />
                                </Listeners>
                            </ext:Button>
                            <ext:ToolbarFill ID="ToolbarFill1" runat="server" />
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <Plugins>
                    <ext:GroupingSummary ID="GroupingSummary1" runat="server" />
                </Plugins>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
                </SelectionModel>
                <Listeners>
                    <Command Fn="commandHandler" />
                    <ColumnResize Handler="updateTotal(#{GridPanel1});" />
                </Listeners>
                <LoadMask ShowMask="true" />
                <SaveMask ShowMask="true" />
                <BottomBar>
                    <ext:Toolbar ID="Toolbar2" runat="server">
                        <Items>
                            <ext:DisplayField ID="DisplayField1" runat="server" Width="50" />
                            <ext:DisplayField ID="ColumnField1" runat="server" DataIndex="TransceiverDate" Cls="total-field"
                                Text="-" />
                            <ext:DisplayField ID="ColumnField2" runat="server" DataIndex="TransceiverTo" Cls="total-field"
                                Text="-" />
                            <ext:DisplayField ID="ColumnField3" runat="server" DataIndex="TransceiverCount" Cls="total-field"
                                Text="-" />
                        </Items>
                    </ext:Toolbar>
                </BottomBar>
            </ext:GridPanel>
        </Items>
    </ext:Viewport>
    <ext:Window ID="DetailsWindow" runat="server" Icon="ApplicationFormEdit" Width="800"
        Height="600" Hidden="true" Modal="true" Constrain="true">
        <AutoLoad  Mode="IFrame" TriggerEvent="show" ReloadOnEvent="true"
            ShowMask="true">
            <Params>
                <ext:Parameter Name="userid" Value="" Mode="Value" />
                <ext:Parameter Name="TransceiverDate" Value="" Mode="Value" />
            </Params>
        </AutoLoad>
        <Buttons>
            <ext:Button ID="Button1" runat="server" Text="关闭">
                <Listeners>
                    <Click Handler="#{DetailsWindow}.hide();" />
                </Listeners>
            </ext:Button>
        </Buttons>
        <Listeners>
            <%--<Hide Handler="if(this.getBody().customerChanged) { dsCustomers.reload(); };" />--%>
        </Listeners>
    </ext:Window>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeaderArea" runat="server">
    <style type="text/css">
        .x-grid3-cell-inner
        {
            font-family: "segoe ui" ,tahoma, arial, sans-serif;
        }
        
        .x-grid-group-hd div
        {
            font-family: "segoe ui" ,tahoma, arial, sans-serif;
        }
        
        .x-grid3-hd-inner
        {
            font-family: "segoe ui" ,tahoma, arial, sans-serif;
            font-size: 12px;
        }
        
        .x-grid3-body .x-grid3-td-Cost
        {
            background-color: #f1f2f4;
        }
        
        .x-grid3-summary-row .x-grid3-td-Cost
        {
            background-color: #e1e2e4;
        }
        
        .total-field
        {
            background-color: #fff;
            font-weight: bold !important;
            color: #000;
            border: solid 1px silver;
            padding: 2px;
            margin-right: 5px;
        }
    </style>
    <script type="text/javascript">
        var updateTotal = function (grid) {
            var fbar = grid.getBottomToolbar(),
                column,
                field,
                width,
                data = {},
                c,
                cs = grid.view.getColumnData();

            for (var j = 0, jlen = grid.store.getCount(); j < jlen; j++) {
                var r = grid.store.getAt(j);

                for (var i = 0, len = cs.length; i < len; i++) {
                    c = cs[i];
                    column = grid.getColumnModel().columns[i];

                    if (column.summaryType) {
                        data[c.name] = Ext.grid.GroupSummary.Calculations[column.summaryType](data[c.name] || 0, r, c.name, data);
                    }
                }
            }

            for (var i = 0; i < grid.getColumnModel().columns.length; i++) {
                column = grid.getColumnModel().columns[i];

                if (column.dataIndex != grid.store.groupField) {
                    field = fbar.findBy(function (item) {
                        return item.dataIndex === column.dataIndex;
                    })[0];

                    if (typeof (field) != 'undefined') {
                        c = cs[i];
                        fbar.remove(field, false);
                        fbar.insert(i, field);
                        width = grid.getColumnModel().getColumnWidth(i);
                        field.setWidth(width - 5);
                        field.setValue((column.summaryRenderer || c.renderer)(data[c.name], {}, {}, 0, i, grid.store));
                    }
                }
            }

            fbar.doLayout();
        }
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="StartupArea" runat="server">
    <script type="text/javascript">
        var commandHandler = function (cmd, record) {
            switch (cmd) {
                case "edit":
                    //debugger;
                    var win =DetailsWindow;
                    win.autoLoad.url = '/Transceiver/TransceiverDetail/';
                    win.autoLoad.params.userid = record.data.UserID;
                    win.autoLoad.params.TransceiverDate = record.data.TransceiverDate;
                    //win.setTitle([record.data.CheckDate, ' '].join(''));
                    win.setTitle([(new Date(record.data.TransceiverDate.replace('-', '/'))).format("Y年m月d日"), ' '].join(''));
                    win.show();
                    break;
            }
        };

        function fillToday() {
            var win = DetailsWindow;
            win.autoLoad.url = '/Transceiver/TransceiverDetail/';
            win.autoLoad.params.userid = _userid;
            win.autoLoad.params.TransceiverDate = new Date().format("Y-m-d");
            //win.setTitle([_today, ' '].join(''));
            win.setTitle([(new Date()).format("Y年m月d日"), ' '].join(''));
            win.show();
        }

        var saveData = function () {
            GridData.setValue(Ext.encode(GridPanel1.getRowsValues({ selectedOnly: false })));
        };

        var submitValue = function (grid, hiddenFormat, format) {
            //debugger;
            hiddenFormat.setValue(format);
            grid.submitData(false);
        };
    </script>
</asp:Content>
